#include "stdafx.h"
#include "Extender.h"
#include "SciTE.h"
#include "GUI.h"

namespace
{
	typedef void( *AccelKeyCommand )( ExtensionAPI* pAPI );

	struct AccelKeyToCommand 
	{
		int modifiers;
		int key;
		AccelKeyCommand cmd;
	};


	class AccelExtension :public Extension
	{
	public:
		AccelExtension()
			:m_pAPI( 0 )
		{
		}
	private:
		bool Initialise(ExtensionAPI *host_)
		{
			m_pAPI = host_;
			return false;
		}
		bool Finalise()
		{
			return false;
		}
		bool Clear()
		{
			return false;
		}
		bool Load(const char *)
		{
			return false;
		}

		bool OnKey(int keyval, int modifiers);
	private:
		ExtensionAPI* m_pAPI;
	};




	void AccelKeyCut( ExtensionAPI* pAPI );
	void AccelKeyCopy( ExtensionAPI* pAPI );
	void AccelKeyTest( ExtensionAPI* pAPI );
	void AccelKeySelectScope( ExtensionAPI* pAPI );


	bool AccelExtension::OnKey( int keyval, int modifiers )
	{
// 		SCMOD_CTRL SCMOD_SHIFT SCMOD_ALT
		static const AccelKeyToCommand CMD[]={
			{ SCMOD_CTRL , 'X' , &AccelKeyCut },
			{ SCMOD_CTRL , 'C' , &AccelKeyCopy },
			{ SCMOD_CTRL|SCMOD_ALT , 'H' , &AccelKeySelectScope },
			{ SCMOD_CTRL , 'K' , &AccelKeyTest },
		};

		for ( int i = 0 ; i < _countof(CMD) ; ++i )
		{
			if( ( CMD[i].modifiers == modifiers )
				&&(CMD[i].key == keyval) )
			{
				AccelKeyCommand func = CMD[i].cmd;
				func( m_pAPI );
				break;
			}
		}
		return false;
	}

	void AccelKeyCut( ExtensionAPI* pAPI )
	{
		if ( pAPI->Send( ExtensionAPI::paneEditor , SCI_GETSELECTIONSTART ) 
			== pAPI->Send( ExtensionAPI::paneEditor , SCI_GETSELECTIONEND ) )
		{
			pAPI->Send( ExtensionAPI::paneEditor , SCI_LINECUT);
		}
		else
		{
		}
	}
	void AccelKeyCopy( ExtensionAPI* pAPI )
	{
		if ( pAPI->Send( ExtensionAPI::paneEditor , SCI_GETSELECTIONSTART ) 
			== pAPI->Send( ExtensionAPI::paneEditor , SCI_GETSELECTIONEND ) )
		{
			pAPI->Send( ExtensionAPI::paneEditor , SCI_LINECOPY);
		}
		else
		{
		}
	}

	void AccelKeySelectScope( ExtensionAPI* pAPI )
	{
		




	}
	void AccelKeyTest( ExtensionAPI* pAPI )
	{
// 		int x = pAPI->Send( ExtensionAPI::paneEditor , SCI_MARKERADD , 0 , 2 );
// 		pAPI->Send( ExtensionAPI::paneEditor , SCI_MARKERSETFORE , x , 0xff );

	}


}





















Extension& RegisterAccelExtension()
{
	static AccelExtension obj;
	return obj;
}


